home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / wf120.zip / MATCH.H < prev    next >
C/C++ Source or Header  |  1992-01-06  |  5KB  |  130 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: match.h
  5.    Author: J. Kercheval
  6.    Created: Sat, 01/05/1991  22:27:18
  7. */
  8.  
  9. /*
  10.  EPSRevision History
  11.  
  12.    J. Kercheval  Wed, 02/20/1991  22:28:37  Released to Public Domain
  13.    J. Kercheval  Sun, 03/10/1991  18:02:56  add is_valid_pattern
  14.    J. Kercheval  Sun, 03/10/1991  18:25:48  add error_type in is_valid_pattern
  15.    J. Kercheval  Sun, 03/10/1991  18:47:47  error return from matche()
  16.    J. Kercheval  Tue, 03/12/1991  22:24:49  Released as V1.1 to Public Domain
  17.    J. Kercheval  Thu, 03/14/1991  22:25:00  remove '\' for DOS file matching
  18.    J. Kercheval  Thu, 03/28/1991  21:03:59  add in PATTERN_ESC & MATCH_LITERAL
  19.    J. Kercheval  Mon, 05/13/1991  21:34:02  ifdef the full match code
  20. */
  21.  
  22. /*
  23.  * Wildcard Pattern Matching
  24.  */
  25.  
  26. /*
  27.  * if FILE_MATCH is defined then the match routine will compile without
  28.  * allowing the literal escape character in the pattern string except within
  29.  * the [..] construct.  The literal escape character '\' is an MSDOS special
  30.  * character and thus is not allowed for file globbing except as a path
  31.  * follow.
  32.  */
  33.  
  34. /* #define FILE_MATCH */
  35.  
  36.  
  37. #ifndef BOOLEAN
  38. #define BOOLEAN int
  39. #define TRUE 1
  40. #define FALSE 0
  41. #endif
  42.  
  43. /* match defines */
  44. #define MATCH_PATTERN  6        /* bad pattern */
  45. #define MATCH_LITERAL  5        /* match failure on literal match */
  46. #define MATCH_RANGE    4        /* match failure on [..] construct */
  47. #define MATCH_ABORT    3        /* premature end of text string */
  48. #define MATCH_END      2        /* premature end of pattern string */
  49. #define MATCH_VALID    1        /* valid match */
  50.  
  51. /* pattern defines */
  52. #define PATTERN_VALID  0        /* valid pattern */
  53. #define PATTERN_ESC   -1        /* literal escape at end of pattern */
  54. #define PATTERN_RANGE -2        /* malformed range in [..] construct */
  55. #define PATTERN_CLOSE -3        /* no end bracket in [..] construct */
  56. #define PATTERN_EMPTY -4        /* [..] contstruct is empty */
  57.  
  58. /*----------------------------------------------------------------------------
  59.  *
  60.  * Match the pattern PATTERN against the string TEXT;
  61.  *
  62.  *      match() returns TRUE if pattern matches, FALSE otherwise.
  63.  *      matche() returns MATCH_VALID if pattern matches, or an errorcode
  64.  *          as follows otherwise:
  65.  *
  66.  *           MATCH_PATTERN  - bad pattern
  67.  
  68. #ifndef FILE_MATCH
  69.  *           MATCH_LITERAL  - match failure on literal mismatch
  70. #endif
  71.  
  72.  *           MATCH_RANGE    - match failure on [..] construct
  73.  *           MATCH_ABORT    - premature end of text string
  74.  *           MATCH_END      - premature end of pattern string
  75.  *           MATCH_VALID    - valid match
  76.  *
  77.  *
  78.  * A match means the entire string TEXT is used up in matching.
  79.  *
  80.  * In the pattern string:
  81.  *      `*' matches any sequence of characters (zero or more)
  82.  *      `?' matches any character
  83.  *      [SET] matches any character in the specified set,
  84.  *      [!SET] or [^SET] matches any character not in the specified set.
  85.  *
  86.  * A set is composed of characters or ranges; a range looks like character
  87.  * hyphen character (as in 0-9 or A-Z).  [0-9a-zA-Z_] is the minimal set of
  88.  * characters allowed in the [..] pattern construct.  Other characters are
  89.  * allowed (ie. 8 bit characters) if your system will support them.
  90.  *
  91.  * To suppress the special syntactic significance of any of `[]*?!^-\', and
  92.  * match the character exactly, precede it with a `\'.
  93.  *
  94.  ---------------------------------------------------------------------------*/
  95.  
  96. BOOLEAN match(char *pattern, char *text);
  97.  
  98. int matche(register char *pattern, register char *text);
  99.  
  100. /*----------------------------------------------------------------------------
  101. *
  102. * Return TRUE if PATTERN has any special wildcard characters
  103. *
  104. ----------------------------------------------------------------------------*/
  105.  
  106. BOOLEAN is_pattern(char *pattern);
  107.  
  108. /*----------------------------------------------------------------------------
  109.  *
  110.  * Return TRUE if PATTERN has is a well formed regular expression according
  111.  * to the above syntax
  112.  *
  113.  * error_type is a return code based on the type of pattern error.  Zero is
  114.  * returned in error_type if the pattern is a valid one.  error_type return
  115.  * values are as follows:
  116.  *
  117.  *   PATTERN_VALID - pattern is well formed
  118.  
  119. #ifndef FILE_MATCH
  120.  *   PATTERN_ESC   - pattern has invalid escape ('\' at end of pattern)
  121. #endif
  122.  
  123.  *   PATTERN_RANGE - [..] construct has a no end range in a '-' pair (ie [a-])
  124.  *   PATTERN_CLOSE - [..] construct has no end bracket (ie [abc-g )
  125.  *   PATTERN_EMPTY - [..] construct is empty (ie [])
  126.  *
  127.  ---------------------------------------------------------------------------*/
  128.  
  129. BOOLEAN is_valid_pattern(char *pattern, int *error_type);
  130.